package com.pine.manager.pineframework.convertors;

import com.pine.common.beans.pineframework.request.SysLogQueryRequest;
import com.pine.common.beans.pineframework.response.SysLogQueryResponse;
import com.pine.common.convertor.EntityConvertor;
import com.pine.common.convertor.QueryConvertor;
import com.pine.dao.pineframework.constants.LogTypeEnum;
import com.pine.dao.pineframework.entity.SysLog;
import com.pine.manager.pineframework.bo.SysLogBo;
import com.pine.manager.pineframework.query.SysLogQuery;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 系统日志表 转换器
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class SysLogConvertor implements EntityConvertor<SysLog, SysLogBo>, QueryConvertor<SysLogBo, SysLogQuery, SysLogQueryRequest, SysLogQueryResponse> {

    @Override
    public abstract SysLog entityBoToEntity(SysLogBo sysLogBo);

    @Override
    public abstract SysLogBo entityToEntityBo(SysLog sysLog);

    @Override
    public abstract SysLogQueryResponse entityBoToQueryResponse(SysLogBo sysLogBo);

    @Override
    public abstract SysLogQuery queryRequestToQuery(SysLogQueryRequest queryRequest);


    @Override
    public abstract List<SysLog> entityBoToEntity(List<SysLogBo> entityBo);

    @Override
    public abstract List<SysLogBo> entityToEntityBo(List<SysLog> entity);


    @AfterMapping
    public void afterMappingEntityBoToEntity(@MappingTarget SysLog sysLog, SysLogBo sysLogBo) {
        // entityBoToEntity() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToEntity()
    }

    @AfterMapping
    public void afterMappingEntityToEntityBo(@MappingTarget SysLogBo sysLogBo, SysLog sysLog) {
        // entityToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityToEntityBo()
    }

    @AfterMapping
    public void afterMappingQueryRequestToQuery(@MappingTarget SysLogQuery sysLogQuery, SysLogQueryRequest sysLogQueryRequest) {
        // queryRequestToQuery() 内部其它代码执行完之后，最后会自动执行 afterMappingQueryRequestToQuery()
    }

    @AfterMapping
    public void afterMappingEntityBoToQueryResponse(@MappingTarget SysLogQueryResponse sysLogQueryResponse, SysLogBo sysLogBo) {
        // entityBoToQueryResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToQueryResponse()
    }


    public LogTypeEnum stringToLogTypeEnum(String code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return LogTypeEnum.of(code);
    }

    public String logTypeEnumToString(LogTypeEnum logTypeEnum) {
        if (Objects.isNull(logTypeEnum)) {
            return null;
        }
        return logTypeEnum.getCode();
    }
}
